/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.amit.concurrency;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author amit
 */
public class Channel<T, V> {

    public LinkedBlockingQueue<T> input = new LinkedBlockingQueue<T>();
    public LinkedBlockingQueue<V> output = new LinkedBlockingQueue<V>();
    public String channelName = null;

    /**
     * The no argument constructor is useful for the "starting" channel, where the input
     * will come from the application rather than another channel
     */
    public Channel(String channelName) {
        this.channelName = channelName;
    }

    /**
     * This constructor will tie the output queue of the parameter Channel to the input queue of this object.
     * @param output
     * @param input
     */
    public Channel(String channelName,Channel<?, T> outputToConnect) {
        this(channelName);
        outputToConnect.output = input;
    }

    public void put(V toPut) {
        output.add(toPut);
    }

    public T get() {
        return input.poll();
    }
}
